import numpy as np


def generate_9x9_orthogonal_latin_squares():
    # 生成原始矩阵 M
    M = np.arange(1, 82).reshape(9, 9)
    print("原始一维数据 D 转换后的矩阵 M:")
    print(M)

    # 生成 8 个正交的 9×9 拉丁方
    orthogonal_latin_squares = []
    for k in range(1, 9):
        latin_square = np.zeros((9, 9), dtype=int)
        for i in range(9):
            for j in range(9):
                latin_square[i, j] = (i + k * j) % 9 + 1
        orthogonal_latin_squares.append(latin_square)

    # 打印 8 个正交的 9×9 拉丁方
    for i, square in enumerate(orthogonal_latin_squares):
        print(f"与 M 正交的第 {i + 1} 个矩阵:")
        print(square)


if __name__ == "__main__":
    generate_9x9_orthogonal_latin_squares()
